import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

import 'index.dart';

class MainPage extends StatefulWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return const _MainViewGetX();
  }
}

class _MainViewGetX extends GetView<MainController> {
  const _MainViewGetX({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return const Center(child: Text("MainPage"));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainController>(
      init: MainController(),
      id: "main",
      builder: (controller) {
        return Scaffold(
          body: PageView(
            controller: controller.pageController,
            onPageChanged: controller.onPageChanged,
            children: controller.pageList,
            physics: const NeverScrollableScrollPhysics(),
          ),
          bottomNavigationBar: Obx(
            () => BottomNavigationBar(
              currentIndex: controller.currentIndex.value,
              onTap: controller.changeTab,
              type: BottomNavigationBarType.fixed,
              selectedItemColor: Colors.blue,
              backgroundColor: Colors.white,
              unselectedItemColor: Colors.grey,
              items: [
                BottomNavigationBarItem(icon: SvgPicture.asset("assets/icon/chat.svg", width: 25, height: 25), label: "聊天"),
                BottomNavigationBarItem(icon: SvgPicture.asset("assets/icon/friend.svg", width: 25, height: 25), label: "好友"),
                BottomNavigationBarItem(icon: SvgPicture.asset("assets/icon/circle.svg", width: 25, height: 25), label: "朋友圈"),
                BottomNavigationBarItem(icon: SvgPicture.asset("assets/icon/person.svg", width: 25, height: 25), label: "我"),
              ],
            ),
          ),
        );
      },
    );
  }
}
